package com.qc.wintrax.adapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.qc.wintrax.R;
import com.qc.wintrax.model.EventInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/8/24.
 */

public class CollectInfoAdapter extends CommonAdapter<EventInfo> {
    private List<EventInfo> eventInfoList;
    private Context mContext;

    public CollectInfoAdapter(Context context, List<EventInfo> datas, int layoutId) {
        super(context, datas, layoutId);
        this.eventInfoList = datas;
        this.mContext = context;
    }

    public void updateList(List<EventInfo> eventInfoList) {
        this.eventInfoList = eventInfoList;
        notifyDataSetChanged();
    }

    @Override
    public void convert(ViewHolder holder, final EventInfo eventInfo) {
        holder.setText(R.id.title_txt, eventInfo.getTitle());
        holder.setText(R.id.publish_name, eventInfo.getPublisher());
        holder.setText(R.id.time_text, eventInfo.getTime());
        holder.setImageResource(R.id.imageView, eventInfo.getImgId());
        holder.setOnClickListener(R.id.delete_img, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setHintView(eventInfo);
//                eventInfoList.remove(eventInfo);
//                notifyDataSetChanged();
            }
        });
    }

    public void setHintView(final EventInfo eventInfo) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        //设置对话框标题
        builder.setTitle(mContext.getResources().getString(R.string.dialog_hint));
        //设置对话框内的文本
        builder.setMessage(mContext.getResources().getString(R.string.hint_content));
        //设置确定按钮，并给按钮设置一个点击侦听，注意这个OnClickListener使用的是DialogInterface类里的一个内部接口
        builder.setPositiveButton(mContext.getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // 执行点击确定按钮的业务逻辑
                eventInfoList.remove(eventInfo);
                notifyDataSetChanged();
            }
        });
        //设置取消按钮
        builder.setNegativeButton(mContext.getResources().getString(R.string.cancle), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // 执行点击取消按钮的业务逻辑
                dialog.dismiss();
            }
        });
        //使用builder创建出对话框对象
        AlertDialog dialog = builder.create();
        //显示对话框
        dialog.show();


    }
}
